package com.wc.算法基础课.A第一讲基础算法.二分.借教室;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/2/28 19:50
 * @description https://www.acwing.com/problem/content/description/505/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1000010;
    static int[] r = new int[N], d = new int[N], s = new int[N], t = new int[N];
    // 差分数组
    static int[] b = new int[N];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) r[i] = sc.nextInt();
        for (int i = 1; i <= m; i++) {
            d[i] = sc.nextInt();
            s[i] = sc.nextInt();
            t[i] = sc.nextInt();
        }

        if (!check(m)) {
            out.println("0");
            out.flush();
            return;
        }
        int l = 1;
        int r = m;
        while (l < r) {
            int mid = l + r >> 1;
            if (check(mid)) r = mid;
            else l = mid + 1;
        }
        out.println("-1");
        out.println(r);
        out.flush();
    }

    static boolean check(int mid) {
        for (int i = 1; i <= n; i++) b[i] = r[i] - r[i - 1];
        for (int i = 1; i <= mid; i++) {
            b[s[i]] -= d[i];
            b[t[i] + 1] += d[i];
        }

        for (int i = 1; i <= n; i++) {
            b[i] += b[i - 1];
            if (b[i] < 0) return true;
        }
        return false;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
